import translations from './Translations';

export const CustomTranslate = (template: any, replacements: any) => {
  replacements = replacements || {};

  // Translate
  template = translations[template] || template;

  // Replace
  return template.replace(/{([^}]+)}/g, function (_, key) {
    const value = replacements[key] || '{' + key + '}';
    return translations[value] || value;
  });
};

export default {
  __init__: ['translate'],
  translate: ['value', CustomTranslate],
};
